// Playground - noun: a place where people can play

import Cocoa


/*********************************************************************
 * The Swift Language Learning  Chapter 05: Control Flow
 *********************************************************************/


let loops = 10
for _ in 1...loops {
	println("loop")
}


let somePoint = (1, 1)
switch somePoint {
case (0, 0):
	println("(0, 0) is at the origin")
case (_, 0):
	println("(\(somePoint.0), 0) is on the x-axis")
case (0, _):
	println("(0, \(somePoint.1)) is on the y-axis")
case (-2...2, -2...2):
	println("(\(somePoint.0), \(somePoint.1)) is inside the box")
default:
	println("(\(somePoint.0), \(somePoint.1)) is outside of the box")
}

//range matching
let count = 3_000_000_000_000
let countedThings = "stars in the Milky Way"

var naturalCount: String
switch count {
case 0:
	naturalCount = "no"
case 1...3:
	naturalCount = "a few"
case 4...9:
	naturalCount = "several"
case 10...99:
	naturalCount = "tens of"
case 100...999:
	naturalCount = "hundreds of"
case 1000...999_999:
	naturalCount = "thousands of"
default:
	naturalCount = "millions and millions of"
}
println("There are \(naturalCount) \(countedThings).")



//binding
let anotherPoint = (2, 0)
switch anotherPoint {
case (let x, 0):
	println("on the x-axis with an x value of \(x)")
case (0, let y):
	println("on the y-axis with a y value of \(y)")
case let (x, y):
	println("somewhere else at (\(x), \(y))")
}


//where switch 
let yetAnotherPoint = (1, -1)
switch yetAnotherPoint {
case let (x, y) where x == y: //1. excute binging trupe (x,y) to (1,-1)
							  //2. juding where condition
							  //3. if true excute case block
	println("(\(x), \(y)) is on the line x == y")
	
case let (x, y) where x == -y:
	println("(\(x), \(y)) is on the line x == -y")
	
case let (x, y):
	println("(\(x), \(y)) is just some arbitrary point")
}



let integerToDescribe = 5
var description = "The number \(integerToDescribe) is"
switch integerToDescribe {
case 2, 3, 5, 7, 11, 13, 17, 19:
	description += " a prime number, and also"
	fallthrough //continue excute case statment. like c without break
case 1:
	description += " some value"
	fallthrough
default:
	description += " an integer."
}
description //The number 5 is a prime number, and also some value an integer.

















